package cn.com.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import cn.com.biz.NoticeBiz;
import cn.com.entity.Notice;

import com.opensymphony.xwork2.ActionSupport;

public class NoticeAction extends ActionSupport implements SessionAware{
	
	private Map<String, Object> session;
	private String noticemsg;
	private Notice notice;
	private NoticeBiz noticebiz;
	public String getNoticemsg() {
		return noticemsg;
	}


	public void setNoticemsg(String noticemsg) {
		this.noticemsg = noticemsg;
	}


	public Notice getNotice() {
		return notice;
	}


	public void setNotice(Notice notice) {
		this.notice = notice;
	}


	public NoticeBiz getNoticebiz() {
		return noticebiz;
	}


	public void setNoticebiz(NoticeBiz noticebiz) {
		this.noticebiz = noticebiz;
	}


	public Map<String, Object> getSession() {
		return session;
	}


	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		session=arg0;
	}
	
	//查询所有公告
		public String selectAllNotice(){
			ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
			noticebiz=(NoticeBiz)ac.getBean("noticebiz");
			List<Notice> list=noticebiz.selectAllNotice();
			session.put("allnoticelist", list);
			return SUCCESS;
		}
		
		//查询一条公告
		public String selectOneNotice(){
			ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
			noticebiz=(NoticeBiz)ac.getBean("noticebiz");
			Notice n=noticebiz.selectOneNotice(notice);
			System.out.println(n.getNoticecontent());
			session.put("onenoticelist", n);
			return SUCCESS;
		}
		//添加一条公告
		public String addNotice(){
			ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
			noticebiz=(NoticeBiz)ac.getBean("noticebiz");
			boolean  bool=noticebiz.addNotice(notice);
			if(bool){
				setNoticemsg("添加新闻成功");
				return SUCCESS;
			}else{
				setNoticemsg("添加新闻失败，请重新添加");
				return ERROR; 
			}
		}
		//更新公告
		public String updateNotice(){
			ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
			noticebiz=(NoticeBiz)ac.getBean("noticebiz");
			boolean  bool=noticebiz.updateNotice(notice);
			if(bool){
				setNoticemsg("更新新闻成功");
				return SUCCESS;
			}else{
				setNoticemsg("更新新闻失败，请重新更新");
				return ERROR; 
			}
		}
		//删除公告
		public String deleteNotice(){
			ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
			noticebiz=(NoticeBiz)ac.getBean("noticebiz");
			boolean  bool=noticebiz.deleteNotice(notice);
			if(bool){
				setNoticemsg("删除新闻成功");
				return SUCCESS;
			}else{
				setNoticemsg("删除新闻失败，请重新删除");
				return ERROR; 
			}
		}	
	
	
	
	
	
}
